package Thread.hongbao;

import java.util.Random;

public class MyThread extends Thread{
    static double money = 100 ;
    static int cont = 3;

    static final  double MIN  = 0.01;


    @Override
    public void run() {
        synchronized (MyThread.class){
            double prize = 0;
            if (cont == 0 ){
                System.out.println("没有抢到红包");
            }else{
                if (cont == 1){
                    prize = money;
                }else {
                    Random random = new Random();
                    prize= random.nextDouble(money - (cont - 1) * MIN);
                    if (prize < MIN ){
                        prize = MIN;
                    }
                }
                cont--;
            }

            money = money-prize;

            System.out.println(getName() +"========="+prize);
        }
    }
}
